package com.js.study.datastructs.stack;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @Author JiangSen
 * @DATE 2023/12/26 11:49
 */
public class let150 {
    public static void main(String[] args) {
        ArrayList<Integer> sum = new ArrayList<>();
        ArrayList<String> operation = new ArrayList<>();
        operation.addAll(Arrays.asList("+","-","*","/"));
        String[] tokens = {"2","1","+","3","*"};
        int total=0;
        for (int i = 0; i < tokens.length; i++) {
            if(operation.contains(tokens[i])){
                switch (tokens[i]){
                    case "+":
                        total = sum.get(sum.size()-2)+sum.get(sum.size()-1);
                        break;
                    case "-":
                        total = sum.get(sum.size()-2)-sum.get(sum.size()-1);
                        break;
                    case "*":
                        total = sum.get(sum.size()-2)*sum.get(sum.size()-1);
                        break;
                    case "/":
                        total = sum.get(sum.size()-2)/sum.get(sum.size()-1);
                        break;
                }
                sum.remove(sum.size()-1);
                sum.remove(sum.size()-1);
                sum.add(total);
            }else{
                sum.add(Integer.valueOf(tokens[i]));
            }
        }
        System.out.println(sum.get(sum.size()-1));
    }
}
